programming4us
           
 
 
SQL Server

Processing and Storing Data in SQL Server 2005 : Data Tracking Validation

- Free product key for windows 10
- Free Product Key for Microsoft office 365
- Malwarebytes Premium 3.7.1 Serial Keys (LifeTime) 2019
12/24/2011 3:35:54 PM
If a record failed to be inserted, nothing stops that record from being lost to us forever. Yes, you could look in the Application log, but this is tedious and not a very good solution. Therefore we are going to add some extra validation, logging, and notification.

Creating Process Error Folder

First we need to create a directory to store our records that fail to get inserted. In the same directory as our incoming directory, add a directory called ProcessError. This is where we will store our records that fail.

You can store the failed records two ways:

  • Create a file per failed record.

  • Create one file and add all failed records to it.

Error Processing Solution

Each solution has its pros and cons. I’m going to use a single file per record because I want to avoid any locking that could occur if I were to have a secondary automated process collecting this data or trying to reprocess it.

For each file we will use a format of fail_record_Guid.fri for failed record information. The GUID portion of our file assures us that no record will be overwritten. We could use DateTime.Now.Ticks as an identifier, but with multiple threads and faster processors running in parallel, it is possible to overwrite files that you are creating because each thread uses the same Ticks value.

Updating the FileWorkerOptions Class

We need to add our process file location to our FileWorkerOptions class so that for each record we create in the database we will know the location of where to save it. Make the changes shown in Listing 1 to your FileWorkerOptions class to add a property that we can set or retrieve as needed.

Listing 1. ProcessError property implementation.
Private m_ProcessError As String

Public Property ProcessError() As String
Get
Return m_ProcessError
End Get
Set(ByVal value As String)
m_ProcessError = value
End Set
End Property

Updating Our Configuration.xml File

For each incoming folder we need to configure the ProcessError folder that we will use for it. Listing 2 shows an example of what your file should now look like.

Listing 2. ProcessError modification in configuration.xml file.
<?xml version="1.0" encoding="utf-8" ?>
<Configuration>
<FileWorkerOptions>
<FileWorkerProperties>
<IncomingPath>c:\tutorials\incoming</IncomingPath>
<OutgoingPath>c:\tutorials\outgoing</OutgoingPath>
<ProcessedFolder>c:\tutorials\processed</ProcessedFolder>
<FileType>*.txt</FileType>
<SmtpServer>testserver</SmtpServer>
<Subject>Test Subject</Subject>
<Message>Found Message</Message>
<Sender>[email protected]</Sender>
<Recipient>[email protected]</Recipient>
<SmtpPort>25</SmtpPort>
<MailEnabled>true</MailEnabled>
<ProcessedError>c:\tutorials\processerror</ProcessedError>
</FileWorkerProperties>
</FileWorkerOptions>
</Configuration>

You can see that I have added the <ProcessError> element and set it equal to my newly created folder path. Each record that fails in my incoming folder or outgoing folder will be written to the ProcessError folder as a separate file.

Updating the FileWorker Class

We will modify several things from the current FileWorker implementation to support additional threading, processing, and notifications. The following sections are required to update the FileWorker class.

Updating the FileWorker Class Constructor

To reflect the support for the new ProcessError property in the FileWorker class, the constructor needs to be updated. In Listing 3, the constructor has been updated to update the local ProcessError property based on the passed in FileWorkerOptions instance.

Listing 3. Updated FileWorker class constructor.
   Public Sub New(ByRef threadaction As ThreadActionState, ByVal
fileworkeroptions As FileWorkerOptions)
m_ThreadAction = threadaction

m_FileWorkerOptions.Input = fileworkeroptions.Input
m_FileWorkerOptions.Output = fileworkeroptions.Output
m_FileWorkerOptions.FileType = fileworkeroptions.FileType
m_FileWorkerOptions.ProcessedPath = fileworkeroptions.ProcessedPath
m_FileWorkerOptions.EmailProperties = fileworkeroptions.EmailProperties
m_FileWorkerOptions.ProcessError = fileworkeroptions.ProcessError
End Sub


Updating the <Tutorials.ThreadFunc> Method

Now that we have created our property to store the location internally and added the value to our configuration file, we have to link the two together using the <threadFunc> method.

In your current threadFunc method, add the bolded code shown in Listing 4; the other non-bolded lines should already exist.

Listing 4. <ThreadFunc> XML configuration read changes.
Private Sub ThreadFunc()
Try
'Load our Configuration File
Dim Doc As XmlDocument = New XmlDocument()
Doc.Load(My.Settings.Configuration)
Dim Options As XmlNode
'Get a pointer to the Outer Node
Options = Doc.SelectSingleNode("//*[local-name()='FileWorkerOptions']")
If (Not Options Is Nothing) Then
'Get a pointer to the first child node of FileWorkerOptions
Dim tmpOptions As System.Xml.XPath.XPathNavigator _
= Options.FirstChild.CreateNavigator()
If (Not tmpOptions Is Nothing) Then
Dim FWOptions As New FileWorkerOptions
Dim children As System.Xml.XPath.XPathNavigator
'Loop through each childe node (FileWorkerOption) and
'get the values. Create a new FileWorkerOptions instance and
'FileWorkerOption instance
Do
Try
children = tmpOptions.SelectSingleNode("IncomingPath")
FWOptions.Input = children.Value

children = tmpOptions.SelectSingleNode("OutgoingPath")
FWOptions.Output = children.Value

children = tmpOptions.SelectSingleNode("FileType")
FWOptions.FileType = children.Value

children = tmpOptions.SelectSingleNode("ProcessedPath")
FWOptions.ProcessedPath = children.Value

children = tmpOptions.SelectSingleNode("ProcessedError")
FWOptions.ProcessError = children.Value

Dim tmpDetail As New EmailDetail
children = tmpOptions.SelectSingleNode("Message")
tmpDetail.Message = children.Value

children = tmpOptions.SelectSingleNode("Subject")
tmpDetail.Subject = children.Value
children = tmpOptions.SelectSingleNode("Sender")
tmpDetail.Sender = children.Value

children = tmpOptions.SelectSingleNode("Recipient")
tmpDetail.Recipient = children.Value

children = tmpOptions.SelectSingleNode("SmtpPort")
tmpDetail.SmtpPort = children.Value

children = tmpOptions.SelectSingleNode("SmtpServer")
tmpDetail.SmtpServer = children.Value

FWOptions.EmailProperties = tmpDetail

Dim tmpFW As New FileWorker(m_ThreadAction, FWOptions)

children = tmpOptions.SelectSingleNode("MailEnabled")
tmpFW.MailEnabled = Convert.ToBoolean(children.Value)

m_WorkerThreads.Add(tmpFW)
tmpFW.Start()
Catch ex As Exception
WriteLogEvent(ex.ToString(), CONFIG_READ_ERROR,
EventLogEntryType.Error, _
My.Resources.Source)
End Try
Loop While (tmpOptions.MoveToNext)
End If
End If
Catch ex As Exception
WriteLogEvent(ex.ToString(), ONSTART_ERROR, _
EventLogEntryType.Error, My.Resources.Source)
Me.Stop()
End Try
End Sub


Now that we have successfully retrieved and set our property value we need to make the code functional.

Other -----------------
- Processing and Storing Data in SQL Server 2005 : Updating the FileWorker Class
- Microsoft SQL Server 2008 R2 : Setting Up Replication (part 4) - Creating Subscriptions
- Microsoft SQL Server 2008 R2 : Setting Up Replication (part 3) - Horizontal and Vertical Filtering
- Microsoft SQL Server 2008 R2 : Setting Up Replication (part 2) - Creating a Publication
- Microsoft SQL Server 2008 R2 : Setting Up Replication (part 1) - Creating a Distributor and Enabling Publishing
- SQL Server 2008 R2 : Basing the Replication Design on User Requirements
- SQL Server 2008 R2 : Planning for SQL Server Data Replication & SQL Server Replication Types
- SQL Server 2008 R2 : Replication Agents
- SQL Server 2008 : Replication - Subscriptions
- SQL Server 2008 : Replication Scenarios
- Protecting SQL Server Data : CELL-LEVEL ENCRYPTION - Special Considerations
- Protecting SQL Server Data : SCHEMA ARCHITECTURE STRATEGIES - Harnessing Linked Servers
- Monitoring SQL Server 2005 Performance : Using Windows System Monitor & Using SQL Server Profiler
- Monitoring SQL Server 2005 Performance : Monitoring and Recording Performance
- SQL Server 2008 R2 : Replication - The Publisher, Distributor, and Subscriber Magazine Metaphor
- SQL Server 2008 R2 : Replication - What Is Replication?
- SQL Server 2008 High Availability : Other HA Techniques That Yield Great Results & High Availability from the Windows Server Family Side
- SQL Server 2008 High Availability : Building Solutions with One or More HA Options
- SQL Server 2008 High Availability : The Fundamentals of HA
- Administering SQL Server 2008 with PowerShell : Step-By-Step Examples (part 4)
 
 
 
Top 10
 
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 2) - Wireframes,Legends
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 1) - Swimlanes
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Formatting and sizing lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Adding shapes to lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Sizing containers
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 3) - The Other Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 2) - The Data Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 1) - The Format Properties of a Control
- Microsoft Access 2010 : Form Properties and Why Should You Use Them - Working with the Properties Window
- Microsoft Visio 2013 : Using the Organization Chart Wizard with new data
- First look: Apple Watch

- 3 Tips for Maintaining Your Cell Phone Battery (part 1)

- 3 Tips for Maintaining Your Cell Phone Battery (part 2)
programming4us programming4us